{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "bdbe13fc",
   "metadata": {},
   "source": [
    "# lesson 1\n",
    "\n",
    "## class 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "142108ee",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "1164a75f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T06:02:00.301408Z",
     "start_time": "2022-03-03T06:02:00.286449Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "1+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "3663c6bd",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T06:42:18.473585Z",
     "start_time": "2022-03-03T06:42:18.455634Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def h(a,b):\n",
    "    '''\n",
    "    @description: use to do summation\n",
    "    @param: two inputs\n",
    "    '''\n",
    "    # sum\n",
    "    c = a+b \n",
    "    return c # 返回结果\n",
    "\n",
    "\n",
    "def h(a,b):\n",
    "    pass\n",
    "\n",
    "h(1,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "9964c755",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T06:47:57.513608Z",
     "start_time": "2022-03-03T06:47:57.494664Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "good\n",
      "good\n",
      "good\n",
      "1\n",
      "good\n",
      "1\n",
      "good\n",
      "1\n",
      "good\n",
      "good\n",
      "1\n",
      "good\n",
      "1\n",
      "good\n",
      "good\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "grade = np.random.randint(50,101,10)\n",
    "\n",
    "for i in grade:\n",
    "    if i >80:\n",
    "        print('1')\n",
    "    print('good')\n",
    " \n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "eef48ea5",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T06:49:41.825901Z",
     "start_time": "2022-03-03T06:49:35.631086Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "what's your name?may\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'may'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# input()  & print\n",
    "\n",
    "input(\"what's your name?\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "0f86cf34",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T06:51:20.985602Z",
     "start_time": "2022-03-03T06:51:20.963149Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello World!\n"
     ]
    }
   ],
   "source": [
    "print('Hello World!')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "e2f4e570",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T06:53:53.588835Z",
     "start_time": "2022-03-03T06:53:53.567892Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 + 2\n"
     ]
    }
   ],
   "source": [
    "a = 1\n",
    "b = 2\n",
    "c = 3\n",
    "print(a, end=\" + \")\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "11a02ec7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T06:57:17.682619Z",
     "start_time": "2022-03-03T06:57:17.663672Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(345, 123)"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name = 345\n",
    "NAME = 123\n",
    "\n",
    "name, NAME"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "f0d4977d",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:00:45.365469Z",
     "start_time": "2022-03-03T06:59:47.021177Z"
    },
    "collapsed": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Welcome to Python 3.9's help utility!\n",
      "\n",
      "If this is your first time using Python, you should definitely check out\n",
      "the tutorial on the Internet at https://docs.python.org/3.9/tutorial/.\n",
      "\n",
      "Enter the name of any module, keyword, or topic to get help on writing\n",
      "Python programs and using Python modules.  To quit this help utility and\n",
      "return to the interpreter, just type \"quit\".\n",
      "\n",
      "To get a list of available modules, keywords, symbols, or topics, type\n",
      "\"modules\", \"keywords\", \"symbols\", or \"topics\".  Each module also comes\n",
      "with a one-line summary of what it does; to list the modules whose name\n",
      "or summary contain a given string such as \"spam\", type \"modules spam\".\n",
      "\n",
      "help> keywords\n",
      "\n",
      "Here is a list of the Python keywords.  Enter any keyword to get more help.\n",
      "\n",
      "False               break               for                 not\n",
      "None                class               from                or\n",
      "True                continue            global              pass\n",
      "__peg_parser__      def                 if                  raise\n",
      "and                 del                 import              return\n",
      "as                  elif                in                  try\n",
      "assert              else                is                  while\n",
      "async               except              lambda              with\n",
      "await               finally             nonlocal            yield\n",
      "\n",
      "\n",
      "You are now leaving help and returning to the Python interpreter.\n",
      "If you want to ask for help on a particular object directly from the\n",
      "interpreter, you can type \"help(object)\".  Executing \"help('string')\"\n",
      "has the same effect as typing a particular string at the help> prompt.\n"
     ]
    }
   ],
   "source": [
    "help()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "02b08c33",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:00:45.938667Z",
     "start_time": "2022-03-03T07:00:45.873846Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 20, 30, 40, 50, 60, 70, 80, 90, 100]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = [10,20,30,40,\\\n",
    "50,60,70,\\\n",
    "80,90,100]\n",
    "a"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1bd61b52",
   "metadata": {},
   "source": [
    "##  六个标准的数据类型\n",
    "\n",
    "Number (数字)\n",
    "\n",
    "int\n",
    "\n",
    "bool\n",
    "\n",
    "float\n",
    "\n",
    "complex （复数）\n",
    "\n",
    "String （字符串）\n",
    "\n",
    "List （列表）\n",
    "\n",
    "Tuple （元组）\n",
    "\n",
    "Sets\n",
    "\n",
    "Dictionary\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7478cde1",
   "metadata": {},
   "source": [
    "### NUMBER"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "9430a397",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:18:21.954036Z",
     "start_time": "2022-03-03T07:18:21.933092Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "hey\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(int, str)"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a , b = 1, 'hey'\n",
    "print(a)\n",
    "print(b)\n",
    "type(a),type(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "696635cc",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:19:56.562740Z",
     "start_time": "2022-03-03T07:19:56.543789Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(float, True)"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# float\n",
    "f = 1.28787\n",
    "type(f), isinstance(f,float)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "263757ff",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:20:32.376545Z",
     "start_time": "2022-03-03T07:20:32.355607Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "bool"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# bool\n",
    "b = True\n",
    "type(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "8d4a2232",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:20:58.831633Z",
     "start_time": "2022-03-03T07:20:58.814666Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1+1j)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "complex"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# complex\n",
    "c = 1+1j\n",
    "print(c)\n",
    "type(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "39e88874",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:21:59.588363Z",
     "start_time": "2022-03-03T07:21:59.566425Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'0b1000'"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bin(8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "f9b84a3e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:25:26.348302Z",
     "start_time": "2022-03-03T07:25:26.332340Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "what's your name\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "str"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# string\n",
    "\n",
    "a = '123'\n",
    "type(a)\n",
    "a = \"what's your name\"\n",
    "print(a)\n",
    "type(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "8d52730a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:27:10.034440Z",
     "start_time": "2022-03-03T07:27:10.008509Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "what\\'s your name\n",
      "hey \n",
      " hey\n"
     ]
    }
   ],
   "source": [
    "a = r'what\\'s your name'\n",
    "print(a)\n",
    "a = 'hey \\\\n hey'\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "d177a377",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:28:05.319934Z",
     "start_time": "2022-03-03T07:28:05.303977Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hey \\\\n hey\n"
     ]
    }
   ],
   "source": [
    "a = r'hey \\\\n hey'\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "90d2aa69",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:33:56.560933Z",
     "start_time": "2022-03-03T07:33:56.538991Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'ade-name-ema'"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = 'grade-name-email'\n",
    "\n",
    "a[0:3] # 首包括，尾不包括\n",
    "a[-1::-1]\n",
    "a[2:-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "cadd9108",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:32:42.434787Z",
     "start_time": "2022-03-03T07:32:42.423813Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'gaenm-mi'"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[::2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "e4b133eb",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:36:04.086390Z",
     "start_time": "2022-03-03T07:36:04.060461Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hey\n",
      "----------\n",
      "next round\n",
      "you\n"
     ]
    }
   ],
   "source": [
    "a = 'hey'\n",
    "b ='you'\n",
    "a*3\n",
    "print(a)\n",
    "print('-'*10)\n",
    "print('next round:')\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aee03556",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:36:32.012039Z",
     "start_time": "2022-03-03T07:36:31.990100Z"
    }
   },
   "source": [
    "# 列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "20f381c2",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:38:02.194095Z",
     "start_time": "2022-03-03T07:38:02.171156Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "list"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ls = [1,2,3,'jiji',True]\n",
    "type(ls)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "0119e4c8",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:39:17.418360Z",
     "start_time": "2022-03-03T07:39:17.391433Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[3, 'jiji', True]"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# slice\n",
    "ls[2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "16357725",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:40:00.894860Z",
     "start_time": "2022-03-03T07:40:00.878900Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[True, 'jiji', 3, 2, 1]"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ls[-1::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "a01fb210",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:41:19.347152Z",
     "start_time": "2022-03-03T07:41:19.334185Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[5, 4, 3, 2, 1]"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ls= [1,2,3,4,5]\n",
    "ls.reverse()\n",
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "6af4721e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:43:57.296721Z",
     "start_time": "2022-03-03T07:43:57.273785Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[5, 4, 3, 'good', 1]"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ls[3] = 'good'\n",
    "ls"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "092dfd10",
   "metadata": {},
   "source": [
    "### 列表的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "e65f78ce",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:46:19.904812Z",
     "start_time": "2022-03-03T07:46:19.888802Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5, 4, 3, 'good', 1, 10, [10, 20, '%store']]\n",
      "[5, 4, 3, 'good', 1, 10, [10, 20, '%store'], 10]\n"
     ]
    }
   ],
   "source": [
    "# append: 在list后面加入一个变量\n",
    "print(ls)\n",
    "ls.append(10)\n",
    "print(ls)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "f2d26e5e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:48:37.657233Z",
     "start_time": "2022-03-03T07:48:37.636289Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, [10, 20, '%store']]\n",
      "----------\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, [10, 20, '%store'], 10, 20, 30]"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ls = [1,2,3]\n",
    "ls.append([10,20,'%store'])\n",
    "print(ls)\n",
    "print('-'*10)\n",
    "ls.extend([10,20,30])\n",
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "8b2a5bee",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:50:17.073080Z",
     "start_time": "2022-03-03T07:50:17.063106Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 长度   len()\n",
    "len(ls)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "a58d6ba8",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:51:55.878095Z",
     "start_time": "2022-03-03T07:51:55.854162Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 'hello', 'hello', [10, 20, '%store'], 10, 20, 30]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 'hello', 'hello', 'hello', [10, 20, '%store'], 10, 20, 30]"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 添加变量\n",
    "# ls.insert(position, var)\n",
    "print(ls)\n",
    "ls.insert(3,'hello')\n",
    "ls\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "61ae9e09",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:53:00.200744Z",
     "start_time": "2022-03-03T07:53:00.178802Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算var出现的次数\n",
    "ls.count('hello')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "id": "218dcbad",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:55:07.058986Z",
     "start_time": "2022-03-03T07:55:07.040026Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['hello', 'hello', 'hello', [10, 20, '%store'], 10, 20, 30]\n",
      "hello\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "['hello', 'hello', [10, 20, '%store'], 10, 20, 30]"
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ls.pop(index)  弹出相应位置的变量\n",
    "print(ls)\n",
    "a = ls.pop(0)\n",
    "print(a)\n",
    "ls\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "a86f217b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:56:19.426139Z",
     "start_time": "2022-03-03T07:56:19.390237Z"
    }
   },
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "list.remove(x): x not in list",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_17316/943293614.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[1;31m# ls.remove(var)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mls\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mremove\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'hello'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      3\u001b[0m \u001b[0mls\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mValueError\u001b[0m: list.remove(x): x not in list"
     ]
    }
   ],
   "source": [
    "# ls.remove(var)\n",
    "ls.remove('hello')\n",
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "id": "9a574af4",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:59:05.076966Z",
     "start_time": "2022-03-03T07:59:05.061020Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[60, 10, 7, 4, 3, 2, 1]"
      ]
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ls.sort()  默认是升序, reverse = True; \n",
    "\n",
    "ls = [1,2,3,10,4,7,60]\n",
    "ls.sort(reverse = True)\n",
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "id": "f85a2496",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-03T07:59:50.916091Z",
     "start_time": "2022-03-03T07:59:50.895151Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[60, 10, 7, 4, 3, 2, 1]\n",
      "[60, 10, 7, 4, 3, 2, 1]\n"
     ]
    }
   ],
   "source": [
    "# copy \n",
    "\n",
    "ls2 = ls\n",
    "print(ls2)\n",
    "ls3 = ls.copy()\n",
    "print(ls3)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d36d7a50",
   "metadata": {},
   "source": [
    "## Class 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8518b57e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T05:59:08.603899Z",
     "start_time": "2022-03-10T05:59:08.593735Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'goodday'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = '  good day  '\n",
    "b = a.strip().replace(' ','')\n",
    "b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "03804728",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:09:29.446405Z",
     "start_time": "2022-03-10T06:09:29.426788Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# list 查找\n",
    "\n",
    "ls = [1,2,3,4,5]\n",
    "10 not in ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "739f819b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:08:35.398321Z",
     "start_time": "2022-03-10T06:08:35.381189Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ls.clear()\n",
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "069346dd",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:09:43.494546Z",
     "start_time": "2022-03-10T06:09:43.474741Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 3, 4, 5]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "del ls[0]\n",
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "5f0b3c67",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:12:26.394860Z",
     "start_time": "2022-03-10T06:12:26.383482Z"
    }
   },
   "outputs": [],
   "source": [
    "# sort  NOTE only number sort\n",
    "ls2 = ['a','A']\n",
    "a = ls2.sort()\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "f450e5ee",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:27:42.617065Z",
     "start_time": "2022-03-10T06:27:42.593264Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "b: [1, 2, 3, 4, 5]\n",
      "c: [1, 2, 3, 4, 5]\n",
      "True True True\n",
      "[10, 20]\n",
      "[1, 2, 3, 4, 5]\n"
     ]
    }
   ],
   "source": [
    "## 复制列表\n",
    "\n",
    "a = [1,2,3,4,5]\n",
    "\n",
    "b = a\n",
    "\n",
    "c = a.copy()\n",
    "\n",
    "print('b:',b)\n",
    "print('c:', c)\n",
    "print(b == a, c ==a, b == c )\n",
    "\n",
    "b =[10,20]\n",
    "print(b)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "7891c6a0",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:22:23.705263Z",
     "start_time": "2022-03-10T06:22:23.684954Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(True, False, False)"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "id(a) == id(b), id(a)== id(c), id(b) == id(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "b41ded15",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:25:17.029645Z",
     "start_time": "2022-03-10T06:25:17.012724Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 2, 3, 4, 5]\n",
      "[0, 2, 3, 4, 5]\n",
      "----------\n",
      "[100, 2, 3, 4, 5]\n",
      "[0, 2, 3, 4, 5]\n"
     ]
    }
   ],
   "source": [
    "b[0] = 0\n",
    "print(b)\n",
    "print(a)\n",
    "print('-'*10)\n",
    "c[0] = 100\n",
    "print(c)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "67ae0b57",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:26:57.699742Z",
     "start_time": "2022-03-10T06:26:57.692297Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "a  = 1\n",
    "b = a\n",
    "\n",
    "b = 10\n",
    "print(b)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "3e5d55fa",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:29:33.805695Z",
     "start_time": "2022-03-10T06:29:33.770640Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   name  age\n",
      "0     1   10\n",
      "1     2   20\n",
      "2     3   30\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "df = pd.DataFrame({'name':[1,2,3],'age':[10,20,30]})\n",
    "print(df)\n",
    "df2 = df  # 慎用 = 复制变量\n",
    "df2 is df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3ecc515d",
   "metadata": {},
   "source": [
    "## tuple"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "c60d2d5f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:32:57.904285Z",
     "start_time": "2022-03-10T06:32:57.883495Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "tuple"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = (1,'jiji',[1,2,3],10)\n",
    "type(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "f5ad143b",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:33:42.806699Z",
     "start_time": "2022-03-10T06:33:42.790918Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('jiji', [1, 2, 3])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[1:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "10602caf",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:34:49.834465Z",
     "start_time": "2022-03-10T06:34:49.819506Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 2, 3, 1, 2, 3)"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(1,2,3)*2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "c1f8f9d3",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:35:36.097126Z",
     "start_time": "2022-03-10T06:35:36.083553Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1,)\n"
     ]
    }
   ],
   "source": [
    "a = (1,)\n",
    "type(a)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "8f2c7ec1",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:37:14.422077Z",
     "start_time": "2022-03-10T06:37:14.402033Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1, 2, 3, ['str', 5, 6])"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = (1,2,3,[4,5,6])\n",
    "a[3][0] = 'str'\n",
    "a"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e7a1179b",
   "metadata": {},
   "source": [
    "## Set"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "d2658e32",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:40:55.602401Z",
     "start_time": "2022-03-10T06:40:55.588508Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3]"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list2 = [1,2,3,3,3,3]\n",
    "list(set(list2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "2e98d3be",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:42:37.816566Z",
     "start_time": "2022-03-10T06:42:37.785982Z"
    }
   },
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'set' object is not subscriptable",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_6868/2514932831.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0ma\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mset\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlist2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0ma\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: 'set' object is not subscriptable"
     ]
    }
   ],
   "source": [
    "a = set(list2)\n",
    "a[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "fa2631cf",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:48:43.699200Z",
     "start_time": "2022-03-10T06:48:43.684241Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1, 10, 12, 2, 3, '5'}"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.add('5')\n",
    "a.update([10,12])\n",
    "a"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a74f5ff5",
   "metadata": {},
   "source": [
    "## 字典"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "08617cdf",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:49:52.056533Z",
     "start_time": "2022-03-10T06:49:52.038581Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'name': 'may', 'age': 18, 'sex': 'male'}"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dict1 = {'name': 'may', 'age': 18, 'sex':'male'}\n",
    "dict1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "699f6a90",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:57:40.669376Z",
     "start_time": "2022-03-10T06:57:40.649429Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'name': ['may', 'kate', '小王'], 'age': 18, 'sex': 'male', 'emal': 'xiaozhang@163.com'}\n",
      "{'name': ['may', 'kate', '小王'], 'age': 18, 'sex': 'male', 'emal': 'xiaozhang@163.com', 'height': 170, 'weight': 100}\n",
      "('weight', 100)\n",
      "{'name': ['may', 'kate', '小王'], 'age': 18, 'sex': 'male', 'emal': 'xiaozhang@163.com', 'height': 170}\n"
     ]
    }
   ],
   "source": [
    "dict1 = {'name': ['may','kate','小王'], 'age': 18, 'sex':'male'}\n",
    "dict1['emal'] = 'xiaozhang@163.com'\n",
    "print(dict1)\n",
    "dict1.update({'height': 170, 'weight':100})\n",
    "print(dict1)\n",
    "# popitem\n",
    "print(dict1.popitem())\n",
    "print(dict1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "40b1d359",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T06:58:18.889317Z",
     "start_time": "2022-03-10T06:58:18.868373Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(dict1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "a1f0cb2e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:00:56.379761Z",
     "start_time": "2022-03-10T07:00:56.355844Z"
    },
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[['may', 'kate', '小王'], 18, 'male', 'xiaozhang@163.com', 170]\n",
      "('age', 18)\n"
     ]
    }
   ],
   "source": [
    "list(dict1.keys())\n",
    "# values\n",
    "print(list(dict1.values()))\n",
    "# items\n",
    "print(list(dict1.items())[1])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "id": "255566a0",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:05:44.160486Z",
     "start_time": "2022-03-10T07:05:44.138544Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'name': ['may', 'kate', '小王'], 'age': 18, 'sex': 'male', 'hey': 10}"
      ]
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dict1 = {'name': ['may','kate','小王'], 'age': 18, 'sex':'male'}\n",
    "dict1['hey'] = dict1.get('hey',10)\n",
    "dict1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "id": "fa216457",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:08:03.663350Z",
     "start_time": "2022-03-10T07:08:03.644394Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "My father was a self-taught mandolin player. He was one of the best string instrument players in our town. He could not read music, but if he heard a tune a few times, he could play it. When he was younger, he was a member of a small country music\n"
     ]
    }
   ],
   "source": [
    "# 练习：计算词频\n",
    "\n",
    "sen = sen = 'My father was a self-taught mandolin player. He was one of the best string instrument players in our town. He could not read music, but if he heard a tune a few times, he could play it. When he was younger, he was a member of a small country music'\n",
    "print(sen)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "id": "51019680",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:39:54.677435Z",
     "start_time": "2022-03-10T07:39:54.653502Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'My': 1,\n",
       " 'father': 1,\n",
       " 'was': 4,\n",
       " 'a': 5,\n",
       " 'self-taught': 1,\n",
       " 'mandolin': 1,\n",
       " 'player': 1,\n",
       " 'He': 2,\n",
       " 'one': 1,\n",
       " 'of': 2,\n",
       " 'the': 1,\n",
       " 'best': 1,\n",
       " 'string': 1,\n",
       " 'instrument': 1,\n",
       " 'players': 1,\n",
       " 'in': 1,\n",
       " 'our': 1,\n",
       " 'town': 1,\n",
       " 'could': 2,\n",
       " 'not': 1,\n",
       " 'read': 1,\n",
       " 'music': 2,\n",
       " 'but': 1,\n",
       " 'if': 1,\n",
       " 'he': 4,\n",
       " 'heard': 1,\n",
       " 'tune': 1,\n",
       " 'few': 1,\n",
       " 'times': 1,\n",
       " 'play': 1,\n",
       " 'it': 1,\n",
       " 'When': 1,\n",
       " 'younger': 1,\n",
       " 'member': 1,\n",
       " 'small': 1,\n",
       " 'country': 1}"
      ]
     },
     "execution_count": 118,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "words_count = {}\n",
    "jishu = 1\n",
    "# for words in sen:\n",
    "#     print('round: ', jishu)\n",
    "#     print('words:', words)\n",
    "#     print('-'*10)\n",
    "#     jishu = jishu + 1\n",
    "\n",
    "for words in sen.replace('.','').replace(',','').split(' '):\n",
    "#     print('round: ', jishu)\n",
    "#     print('words:', words)\n",
    "#     print('-'*10)\n",
    "#     jishu = jishu + 1\n",
    "    words_count[words] = words_count.get(words, 0)+ 1 \n",
    "words_count\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "id": "88e4fea6",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:41:49.178975Z",
     "start_time": "2022-03-10T07:41:49.160026Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'a': 'b', 'c': 'd'}\n"
     ]
    }
   ],
   "source": [
    "a=[('a','b'),('c','d')]\n",
    "b=dict(a)\n",
    "print(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "id": "a50c761a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:39:13.824428Z",
     "start_time": "2022-03-10T07:39:13.788520Z"
    }
   },
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "unbound method dict.get() needs an argument",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_6868/934030674.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mhelp\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdict\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: unbound method dict.get() needs an argument"
     ]
    }
   ],
   "source": [
    "help(dict.get()\\)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "id": "18d3c957",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:42:59.980920Z",
     "start_time": "2022-03-10T07:42:59.933051Z"
    }
   },
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "invalid literal for int() with base 10: '1a23'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_6868/3334936319.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0ma\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'1a23'\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0ma\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      3\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mValueError\u001b[0m: invalid literal for int() with base 10: '1a23'"
     ]
    }
   ],
   "source": [
    "a = '1a23'\n",
    "a = int(a)\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "id": "f76b5bf7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:43:32.548933Z",
     "start_time": "2022-03-10T07:43:32.532976Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eval('1+1')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "785d6224",
   "metadata": {},
   "source": [
    "## 算数运算符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "id": "85d50b2a",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:46:24.888907Z",
     "start_time": "2022-03-10T07:46:24.872949Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(579, -333, 56088, 0.26973684210526316, 87, 3)"
      ]
     },
     "execution_count": 124,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = 123\n",
    "b = 456\n",
    "a+b, a-b, a*b, a/b, b % a, b//a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "id": "f839ab42",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:46:57.851496Z",
     "start_time": "2022-03-10T07:46:57.826571Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1000"
      ]
     },
     "execution_count": 125,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = 10 \n",
    "a**3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "id": "f08dfdd7",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:47:34.991125Z",
     "start_time": "2022-03-10T07:47:34.969186Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "579"
      ]
     },
     "execution_count": 127,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = '123'\n",
    "int(a)+b"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "id": "65aef619",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:50:26.251487Z",
     "start_time": "2022-03-10T07:50:26.228538Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.2"
      ]
     },
     "execution_count": 132,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = 1 \n",
    "a /= 5  #  a = a/5\n",
    "a"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7049d05f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:54:44.459235Z",
     "start_time": "2022-03-10T07:54:44.440286Z"
    }
   },
   "source": [
    "# if not 0:\n",
    "    print('hey')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "id": "b91c3dfa",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-10T07:56:18.413736Z",
     "start_time": "2022-03-10T07:56:18.403693Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 145,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "0 or 10 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "2499fdb1",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-17T05:48:58.901952Z",
     "start_time": "2022-03-17T05:48:58.883057Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "today is Monday. \n"
     ]
    }
   ],
   "source": [
    "weekday = 'Monday. '\n",
    "sen = 'today is %s' % weekday\n",
    "print(sen)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8cdf436c",
   "metadata": {},
   "outputs": [],
   "source": [
    "sen = 'XXXXX:', a, 'XXX:', b \n",
    "print(sen)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ad003cc0",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-17T05:49:45.032440Z",
     "start_time": "2022-03-17T05:49:45.014107Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name:june, age:20\n"
     ]
    }
   ],
   "source": [
    "\n",
    "print('name:%s, age:%d' % ('june',20))\n",
    "# s:str, d:int，f：float"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "67fd204f",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-17T05:52:37.148774Z",
     "start_time": "2022-03-17T05:52:37.130772Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "today s Fri, tmr is Monday. \n"
     ]
    }
   ],
   "source": [
    "weekday2 = 'Fri'\n",
    "sen = 'today s {1}, tmr is {0}'.format(weekday,weekday2)\n",
    "print(sen)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d838359c",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-17T05:54:09.015928Z",
     "start_time": "2022-03-17T05:54:09.004642Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "M0:190,M1:60,M2:7\n"
     ]
    }
   ],
   "source": [
    "# 传入list\n",
    "m=[7,60,190]\n",
    "print('M0:{0[2]},M1:{0[1]},M2:{0[0]}'.format(m))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e2f655da",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 传入dictionary\n",
    "m2={'m0':7,'m1':60,'m2':190}\n",
    "print('M0:{m[m0]},M1:{m[m1]},M2:{m[m2]}'.format(m=m2))\n",
    "print('M0:{0[m0]},M1:{0[m1]},M2:{0[m2]}'.format(m2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "34a4e835",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-17T05:59:14.247058Z",
     "start_time": "2022-03-17T05:59:14.229794Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "start\n",
      "选择性语句的执行\n",
      "end\n"
     ]
    }
   ],
   "source": [
    "print('start')\n",
    "if True:\n",
    "    print('选择性语句的执行')\n",
    "print('end')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "9accd68e",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-17T06:03:18.452063Z",
     "start_time": "2022-03-17T06:03:16.193577Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "what's your grade?30\n",
      "不及格\n"
     ]
    }
   ],
   "source": [
    "grade = input(\"what's your grade?\")\n",
    "if int(grade) >= 60:\n",
    "    print('及格')\n",
    "else:\n",
    "    print('不及格')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "0f3196ae",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-17T06:06:25.576038Z",
     "start_time": "2022-03-17T06:06:24.306855Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "what's your grade?\n"
     ]
    },
    {
     "ename": "ValueError",
     "evalue": "invalid literal for int() with base 10: ''",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m--------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                   Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_15424/1140636678.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0mgrade\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0minput\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"what's your grade?\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[1;32mif\u001b[0m \u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mgrade\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m>=\u001b[0m \u001b[1;36m85\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      3\u001b[0m     \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'优秀'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[1;32melif\u001b[0m \u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mgrade\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m>=\u001b[0m \u001b[1;36m75\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m     \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'良好'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mValueError\u001b[0m: invalid literal for int() with base 10: ''"
     ]
    }
   ],
   "source": [
    "grade = input(\"what's your grade?\")\n",
    "if int(grade) >= 85:\n",
    "    print('优秀')\n",
    "elif int(grade) >= 75:\n",
    "    print('良好')\n",
    "elif int(grade) >= 60:\n",
    "    print('及格')\n",
    "else:\n",
    "    print('不及格')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5313998f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 一本书中的例子\n",
    "grade = int(input('输入成绩：'))\n",
    "\n",
    "if grade >= 60:\n",
    "    print('jige')\n",
    "elif grade >=70:\n",
    "    print('良好')\n",
    "elif grade >=85:\n",
    "    print('youxiu')\n",
    "else:\n",
    "    print('不及格')\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "042cd410",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-17T06:14:47.268686Z",
     "start_time": "2022-03-17T06:14:47.252996Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99  "
     ]
    }
   ],
   "source": [
    "num  = 1\n",
    "while num>0:\n",
    "    print(num, end ='  ')\n",
    "    num += 1  # num = num - 1\n",
    "    if num == 100:\n",
    "        break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "e87c1a89",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-03-17T06:17:07.540931Z",
     "start_time": "2022-03-17T06:17:07.530995Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1; 4; 9; 16; 36; "
     ]
    }
   ],
   "source": [
    "# 遍历列表\n",
    "a=[1,2,3,4,6]\n",
    "for i in a:\n",
    "    print(i*i,end='; ')\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "64670f38",
   "metadata": {},
   "outputs": [],
   "source": [
    "ls = [10,4,7,3,8]\n",
    "for (pos, value) in enumerate(ls):\n",
    "    print(pos)\n",
    "    print(value)\n",
    "    print('-'*20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "af71c310",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "may\n",
      "22\n",
      "econ\n"
     ]
    }
   ],
   "source": [
    "dict1 = {'name':'may','age':22, 'major':'econ'}\n",
    "for i in dict1:\n",
    "    print(dict1[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "fa0cd8f4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('name', 'may'), ('age', 22), ('major', 'econ')]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(dict1.items())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "583e2c74",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'name': 'may', 'age': 22, 'major': 'econ'}\n",
      "{'may': 'name', 22: 'age', 'econ': 'major'}\n"
     ]
    }
   ],
   "source": [
    "dict2 = {}\n",
    "for (key,value) in dict1.items():\n",
    "    dict2[value] = key \n",
    "print(dict1)\n",
    "print(dict2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "7713f652",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(10,0,-1))  # range(start, end, step)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "9fe67b9b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n"
     ]
    }
   ],
   "source": [
    "a = [1,2,3,4,5,6,7]\n",
    "for i in range(0, len(a)):\n",
    "    print(a[i])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f0cfe8e3",
   "metadata": {},
   "source": [
    "1*1=1   1*2=2   1*3=3   1*4=4   1*5=5   1*6=6   1*7=7   1*8=8   1*9=9   \n",
    "2*1=2   2*2=4   2*3=6   2*4=8   2*5=10  2*6=12  2*7=14  2*8=16  2*9=18  \n",
    "3*1=3   3*2=6   3*3=9   3*4=12  3*5=15  3*6=18  3*7=21  3*8=24  3*9=27  \n",
    "4*1=4   4*2=8   4*3=12  4*4=16  4*5=20  4*6=24  4*7=28  4*8=32  4*9=36  \n",
    "5*1=5   5*2=10  5*3=15  5*4=20  5*5=25  5*6=30  5*7=35  5*8=40  5*9=45  \n",
    "6*1=6   6*2=12  6*3=18  6*4=24  6*5=30  6*6=36  6*7=42  6*8=48  6*9=54  \n",
    "7*1=7   7*2=14  7*3=21  7*4=28  7*5=35  7*6=42  7*7=49  7*8=56  7*9=63  \n",
    "8*1=8   8*2=16  8*3=24  8*4=32  8*5=40  8*6=48  8*7=56  8*8=64  8*9=72  \n",
    "9*1=9   9*2=18  9*3=27  9*4=36  9*5=45  9*6=54  9*7=63  9*8=72  9*9=81  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "54c1652a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1*1=1  1*2=2  1*3=3  1*4=4  1*5=5  1*6=6  1*7=7  1*8=8  1*9=9  \n",
      "2*1=2  2*2=4  2*3=6  2*4=8  2*5=10 2*6=12 2*7=14 2*8=16 2*9=18 \n",
      "3*1=3  3*2=6  3*3=9  3*4=12 3*5=15 3*6=18 3*7=21 3*8=24 3*9=27 \n",
      "4*1=4  4*2=8  4*3=12 4*4=16 4*5=20 4*6=24 4*7=28 4*8=32 4*9=36 \n",
      "5*1=5  5*2=10 5*3=15 5*4=20 5*5=25 5*6=30 5*7=35 5*8=40 5*9=45 \n",
      "6*1=6  6*2=12 6*3=18 6*4=24 6*5=30 6*6=36 6*7=42 6*8=48 6*9=54 \n",
      "7*1=7  7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49 7*8=56 7*9=63 \n",
      "8*1=8  8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64 8*9=72 \n",
      "9*1=9  9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81 \n"
     ]
    }
   ],
   "source": [
    "for row in range(1,10):\n",
    "    # print(row)\n",
    "    for col in range(1,10):\n",
    "        print('{}*{}={:<2}'.format(row,col,row*col), end = ' ')\n",
    "    print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "2fc0f955",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1*1=1  \n",
      "2*1=2  2*2=4  \n",
      "3*1=3  3*2=6  3*3=9  \n",
      "4*1=4  4*2=8  4*3=12 4*4=16 \n",
      "5*1=5  5*2=10 5*3=15 5*4=20 5*5=25 \n",
      "6*1=6  6*2=12 6*3=18 6*4=24 6*5=30 6*6=36 \n",
      "7*1=7  7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49 \n",
      "8*1=8  8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64 \n",
      "9*1=9  9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81 \n"
     ]
    }
   ],
   "source": [
    "for row in range(1,10):\n",
    "    # print(row)\n",
    "    for col in range(1,row+1):\n",
    "        print('{}*{}={:<2}'.format(row,col,row*col), end = ' ')\n",
    "    print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "eff761b1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9*1=9  9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81 \n",
      "8*1=8  8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64 \n",
      "7*1=7  7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49 \n",
      "6*1=6  6*2=12 6*3=18 6*4=24 6*5=30 6*6=36 \n",
      "5*1=5  5*2=10 5*3=15 5*4=20 5*5=25 \n",
      "4*1=4  4*2=8  4*3=12 4*4=16 \n",
      "3*1=3  3*2=6  3*3=9  \n",
      "2*1=2  2*2=4  \n",
      "1*1=1  \n"
     ]
    }
   ],
   "source": [
    "for row in range(9,0,-1):\n",
    "    # print(row)\n",
    "    for col in range(1,row+1):\n",
    "        print('{}*{}={:<2}'.format(row,col,row*col), end = ' ')\n",
    "    print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "cd1de9d1",
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(10):\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "ad561436",
   "metadata": {},
   "outputs": [],
   "source": [
    "def mysum(num):\n",
    "    '''\n",
    "    这是一个计算加总的函数\n",
    "    参数是int类型\n",
    "    返回值是int类型\n",
    "    '''\n",
    "    pass\n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "b5b5a115",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function mysum in module __main__:\n",
      "\n",
      "mysum(num)\n",
      "    这是一个计算加总的函数\n",
      "    参数是int类型\n",
      "    返回值是int类型\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(mysum)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "8b420983",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\n    这是一个计算加总的函数\\n    参数是int类型\\n    返回值是int类型\\n    '"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mysum.__doc__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "bed64fe1",
   "metadata": {},
   "outputs": [],
   "source": [
    "def power(x):\n",
    "    '''\n",
    "    x: int, float\n",
    "    '''\n",
    "    return x**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "8748b4d2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "power(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "97d865f8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(100000, 9765625)"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def power(x,n):\n",
    "    '''\n",
    "    x: int, float\n",
    "    '''\n",
    "    return x**n\n",
    "power(10,5), power(5,10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "76120e33",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10000"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# n = 4\n",
    "def power(x, n = 4, m =5, k = 6):\n",
    "    return x**n\n",
    "\n",
    "power(10, m = 4, k = 7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "65b88744",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 'end']"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def add_end(x = []):\n",
    "    x.append('end')\n",
    "    return x\n",
    "\n",
    "add_end([1,2,3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "a11621d5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['end']"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 修改\n",
    "def add_end(x = None):\n",
    "    if x is None:\n",
    "        x = [];\n",
    "\n",
    "    x.append('end')\n",
    "    return x\n",
    "\n",
    "add_end()\n",
    "add_end()\n",
    "add_end()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "01e6fd80",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2, 4, 6, 'end']"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "add_end([2,4,6])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "21ec282d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['end']"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "add_end()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "5d3b1c32",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['end', 'end', 'end', 'end', 'end']"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "add_end()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "a8a284f7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "ji\n"
     ]
    }
   ],
   "source": [
    "def fun2(*arg):\n",
    "    # print(arg)\n",
    "    for i in arg:\n",
    "        print(i)\n",
    "    \n",
    "# 以元组(tuple)的方式传入参数\n",
    "fun2(1,2,3,'ji')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "54451707",
   "metadata": {},
   "source": [
    "练习：计算数字之和, a+b+c+d+…"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "bfa4d554",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "64"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ls = [4,32,2,7,9,10]\n",
    "\n",
    "def cal_sum(x):\n",
    "    total = 0\n",
    "    for i in x:\n",
    "        total  += i\n",
    "    return total\n",
    "\n",
    "cal_sum(ls)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "699112f6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def cal_sum2(*x):\n",
    "    total = 0\n",
    "    for i in x:\n",
    "        total  += i\n",
    "    return total\n",
    "\n",
    "cal_sum2(2,1,5,7,10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "303ed9f2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ls = [1,2,3]\n",
    "cal_sum2(ls[0],ls[1],ls[2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "ae231251",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cal_sum2(*ls)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "394aa0d3",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "fun1() takes 0 positional arguments but 3 were given",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_8444/1891694608.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      5\u001b[0m \u001b[1;31m# fun1(a=1,b=2,c=3)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 6\u001b[1;33m \u001b[0mfun1\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: fun1() takes 0 positional arguments but 3 were given"
     ]
    }
   ],
   "source": [
    "# **kargs表示收集关键字参数（带有默认值的参数）\n",
    "def fun1(**kargs):\n",
    "    print(kargs)\n",
    "\n",
    "# fun1(a=1,b=2,c=3)\n",
    "fun1(1,2,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "8fe36a68",
   "metadata": {},
   "outputs": [],
   "source": [
    "def sample(*ta,**dict1):\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "47df3d2a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "(2, 3, 'ty')\n",
      "{'c': 2, 'n': 10}\n"
     ]
    }
   ],
   "source": [
    "def test(value1,*arg, **kargs):\n",
    "    print(value1)\n",
    "    print(arg)\n",
    "    print(kargs)\n",
    "    \n",
    "test(1,2,3,'ty',c=2,n=10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "11651ff1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "xiaozhang\n"
     ]
    }
   ],
   "source": [
    "name  = 'xiaozhang'\n",
    "\n",
    "def pname():\n",
    "    print(name)\n",
    "    return\n",
    "\n",
    "pname()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "3e6a25fa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "may\n",
      "22\n",
      "--------------------\n",
      "xiaozhang\n"
     ]
    },
    {
     "ename": "NameError",
     "evalue": "name 'age' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_8444/1601777846.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      9\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'-'\u001b[0m\u001b[1;33m*\u001b[0m\u001b[1;36m20\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     10\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 11\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mage\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m: name 'age' is not defined"
     ]
    }
   ],
   "source": [
    "name  = 'xiaozhang'\n",
    "\n",
    "def pname(name, age):\n",
    "    print(name)\n",
    "    print(age)\n",
    "    return\n",
    "\n",
    "pname('may',22)\n",
    "print('-'*20)\n",
    "print(name)\n",
    "print(age)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "8a9d5dab",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "may\n",
      "22\n",
      "may\n"
     ]
    }
   ],
   "source": [
    "#函数外定义的称为全局变量\n",
    "name = 'june'\n",
    "# def fun1():\n",
    "#     print(name) # name可以在函数内部调用\n",
    "count1 = 0\n",
    "count2 = 0\n",
    "def fun2(str1, int1):\n",
    "    global name  # 声明是全局变量\n",
    "    name = str1\n",
    "    print(name)    \n",
    "    age= int1 # 局部变量\n",
    "    print(age)\n",
    "    return\n",
    "\n",
    "fun2('may',22)\n",
    "print(name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "9fc5b94a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "may\n",
      "22\n"
     ]
    }
   ],
   "source": [
    "function1 = fun2\n",
    "function1('may',22)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "4c52c0ec",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def sample1(a,b):\n",
    "    return a+b,a-b,a*b\n",
    "\n",
    "sample1(3,4)[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "5c2d8379",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ls = [1,2,3,4,5]\n",
    "[i*i   for i in ls]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "a16e6abb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 16, 25]"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[i*i for i in ls if i != 3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "7404cf2c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['f', 'f', 'f', 'm', 'm', 'm', 'f', 'm', 'f', 'm', 'f', 'm', 'f']"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ls = list('fffmmmfmfmfmf')\n",
    "ls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "e5ced9ff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1]"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[1 if sex =='f' else 0 for sex in ls]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "766f23b0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 1, 1, 1, 1, 1, 1]"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[1 for sex in ls if sex =='f' ]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "a00b4cf0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = 3 \n",
    "b = 2 if a == 3 else 0\n",
    "b"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ff63fa4f",
   "metadata": {},
   "source": [
    "## class 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "95821007",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a1', 'a2', 'a3', 'b1', 'b2', 'b3', 'c1', 'c2', 'c3']"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#练习：'abc','123'，想让 a 和 1,2,3 每个字符生成新的字符串，b,c也是\n",
    "a='abc'\n",
    "b='123'\n",
    "\n",
    "new_list=[]\n",
    "for i in a:\n",
    "    for j in b:\n",
    "        new_list.append(i+j)\n",
    "new_list\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "cdea0df5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['a1', 'b2', 'c3']"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a='abc'\n",
    "b='123'\n",
    "\n",
    "c = [i+j for i in a for j in b]\n",
    "c\n",
    "\n",
    "# 对应位置拼接\n",
    "[i+j for i,j in zip(a,b)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ec6c54f3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<zip object at 0x00000178C689FD80>\n",
      "[(1, 7), (2, 8), (3, 9)]\n"
     ]
    }
   ],
   "source": [
    "# zip\n",
    "\n",
    "a =[ 1,2,3]\n",
    "b = [7,8,9]\n",
    "print(zip(a,b))\n",
    "print(list(zip(a,b)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "030eb6af",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('a', '1'), ('b', '2'), ('c', '3')]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = list(zip(a,b))\n",
    "c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "e0a93053",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('a', 'b', 'c'), ('1', '2', '3')]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(zip(*c))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "e8cf9448",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 1, 0, 1, 0, 1, 1, 0, 0]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = list('ffmfmffmm')\n",
    "[1 if sex=='f' else 0 for sex in a]\n",
    "# expression 中也可以加条件语句；"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "e446b87c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[7, 8, 9, 1, 2, 3, 4, 5, 6]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 练习1： \n",
    "# c = [[7,8,9],[1,2,3],[4,5,6]]  转为 [7, 8, 9, 1, 2, 3, 4, 5, 6]\n",
    "\n",
    "c = [[7,8,9],[1,2,3],[4,5,6]]  \n",
    "\n",
    "[  j   for i in c for j in i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "7eecdd9a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.141592653589793\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[3.1, 3.14, 3.142, 3.1416, 3.14159]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 练习2： 输出保留1-5位小数的圆周率\n",
    "from math import pi\n",
    "print(pi)\n",
    "# [str(round(pi, i)) for i in range(1, 6)]\n",
    "\n",
    "[round(pi,i)   for i in range(1,6)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "72ef13ce",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1*9=9  2*9=18  3*9=27  4*9=36  5*9=45  6*9=54  7*9=63  8*9=72  9*9=81'"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "row = 9\n",
    "'  '.join(['{}*{}={}'.format(col,row,col*row) for col in range(1,row+1)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "b60d3df2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1*1=1 \n",
      "1*2=2   2*2=4 \n",
      "1*3=3   2*3=6   3*3=9 \n",
      "1*4=4   2*4=8   3*4=12  4*4=16\n",
      "1*5=5   2*5=10  3*5=15  4*5=20  5*5=25\n",
      "1*6=6   2*6=12  3*6=18  4*6=24  5*6=30  6*6=36\n",
      "1*7=7   2*7=14  3*7=21  4*7=28  5*7=35  6*7=42  7*7=49\n",
      "1*8=8   2*8=16  3*8=24  4*8=32  5*8=40  6*8=48  7*8=56  8*8=64\n",
      "1*9=9   2*9=18  3*9=27  4*9=36  5*9=45  6*9=54  7*9=63  8*9=72  9*9=81\n"
     ]
    }
   ],
   "source": [
    "print('\\n'.join(['  '.join(['{}*{}={:<2}'.format(col,row,col*row) for col in range(1,row+1)]) for row in range(1,10)]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "5f5b8a36",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "too many values to unpack (expected 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_17596/2499608102.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[0mc\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfun\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m10\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 5\u001b[1;33m \u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0my\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfun\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m10\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      6\u001b[0m \u001b[1;31m# print(x)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      7\u001b[0m \u001b[1;31m# print(y)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mValueError\u001b[0m: too many values to unpack (expected 2)"
     ]
    }
   ],
   "source": [
    "def fun(a,b):\n",
    "    return a,b,a+b  #存储为元组\n",
    "\n",
    "c = fun(1,10)\n",
    "x,y = fun(1,10)\n",
    "# print(x)\n",
    "# print(y)\n",
    "# print(z)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d3724518",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "120"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算 n!\n",
    "\n",
    "# def fact(n):\n",
    "#     result = 1\n",
    "#     for i in range(1,n+1):\n",
    "#         result  = result *i\n",
    "#     return result\n",
    "# fact(5)\n",
    "\n",
    "# method:\n",
    "def fact2(n):\n",
    "    if n == 1:\n",
    "        return 1   # 终止条件\n",
    "    return n*fact2(n-1)\n",
    "\n",
    "fact2(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7dcacbfe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "102334155"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 练习：计算斐波那契额数列，1,1,2,3,5,8..., 的第n项的数值\n",
    "def fib(n):\n",
    "    if (n == 1) or (n == 2):\n",
    "        return 1\n",
    "    return fib(n-1) + fib(n-2)\n",
    "\n",
    "fib(40)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "e0291d8c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "102334155"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def fib2(n):\n",
    "    if (n == 1) or (n == 2):\n",
    "        return 1\n",
    "    pos = 3 \n",
    "    a = 1\n",
    "    b = 1\n",
    "    # for pos in range(3, n+1):\n",
    "    while pos <= n:\n",
    "        c = a + b\n",
    "        a = b\n",
    "        b = c\n",
    "        pos += 1\n",
    "    return c\n",
    "\n",
    "fib2(40)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "c51c396b",
   "metadata": {},
   "outputs": [],
   "source": [
    "def div(n):\n",
    "    try:\n",
    "        print('in try block')\n",
    "        _ = 10/n\n",
    "        print('result: ', _)\n",
    "    except ZeroDivisionError as e:\n",
    "    # except Exception as e:\n",
    "        print('except: ', e)\n",
    "    finally:\n",
    "        print('finally')\n",
    "    print('END')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "dc1ce898",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in try block\n",
      "finally\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "unsupported operand type(s) for /: 'int' and 'str'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_16052/349336183.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdiv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'c'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_16052/3574373924.py\u001b[0m in \u001b[0;36mdiv\u001b[1;34m(n)\u001b[0m\n\u001b[0;32m      2\u001b[0m     \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m         \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'in try block'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m         \u001b[0m_\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m10\u001b[0m\u001b[1;33m/\u001b[0m\u001b[0mn\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      5\u001b[0m         \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'result: '\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0m_\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      6\u001b[0m     \u001b[1;32mexcept\u001b[0m \u001b[0mZeroDivisionError\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for /: 'int' and 'str'"
     ]
    }
   ],
   "source": [
    "div('c')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "1d3e270b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "in try block\n",
      "except:  division by zero\n",
      "finally\n",
      "END\n"
     ]
    }
   ],
   "source": [
    "def div(n):\n",
    "    try:\n",
    "        print('in try block')\n",
    "        _ = 10/n\n",
    "        print('result: ', _)\n",
    "    except BaseException as e:\n",
    "    # except Exception as e:\n",
    "        print('except: ', e)\n",
    "        _ = None\n",
    "    finally:\n",
    "        print('finally')\n",
    "    print('END')\n",
    "div(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "ca3b2a40",
   "metadata": {},
   "outputs": [],
   "source": [
    "c = lambda x: x*x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "87968e3c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "67648763",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'c:\\\\Users\\\\illus\\\\OneDrive\\\\GIT\\\\data-analysis\\\\course-coding'"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os\n",
    "\n",
    "os.getcwd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "e1a8a0ab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'c:\\\\Users\\\\illus\\\\OneDrive\\\\GIT\\\\data-analysis\\\\course-coding\\\\try'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " # 相对路径，相对于文件本身的位置定位\n",
    "    # ./： 在当前文件所在的文件夹目录下\n",
    "    # ../ 对于当前文件夹的上一级文件夹\n",
    "os.chdir('c:\\\\Users\\\\illus\\\\OneDrive\\\\GIT\\\\data-analysis\\\\course-coding')\n",
    "os.chdir('./try')\n",
    "os.getcwd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "f8c2ee5a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'c:\\\\Users\\\\illus\\\\OneDrive\\\\GIT\\\\data-analysis\\\\lecture-python\\\\raw-data'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.chdir('../../lecture-python/raw-data')\n",
    "os.getcwd()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1922e1c5",
   "metadata": {},
   "source": [
    "# class 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b454b235",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b2fb17a5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'c:\\\\Users\\\\illus\\\\OneDrive\\\\GIT\\\\data-analysis\\\\course-coding'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.getcwd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "09812519",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ".ipynb_checkpoints\n",
      "python数据结构.ipynb\n",
      "try\n"
     ]
    }
   ],
   "source": [
    "a = os.listdir()\n",
    "for i in a:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "c898b3be",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 36, 49, 64, 81]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 将 a=[1,2,3,4,5,6,7,8,9] 转换为 [1*1,2*2,..., 9*9]\n",
    "\n",
    "a=[1,2,3,4,5,6,7,8,9] \n",
    "print([i*i for i in a])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "0df4866c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "this is round :  1\n",
      "5\n",
      "----------\n",
      "this is round :  2\n",
      "4\n",
      "----------\n",
      "this is round :  3\n",
      "3\n",
      "----------\n",
      "this is round :  4\n",
      "2\n",
      "----------\n",
      "this is round :  5\n",
      "1\n",
      "----------\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[25, 16, 9, 4, 1]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a=list('54321')\n",
    "\n",
    "count = 1\n",
    "def f(x):\n",
    "    global count\n",
    "    print('this is round : ', count)\n",
    "    print(x)\n",
    "    print('-'*10)\n",
    "    count = count + 1\n",
    "    return int(x)*int(x)\n",
    "\n",
    "list(map(f, a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "f3227d8e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(6, 5), (6, 8), (6, 9), (6, 8), (6, 5)]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a=list('54321')\n",
    "\n",
    "\n",
    "def f(x):\n",
    "    return int(x)*int(x)\n",
    "\n",
    "list(map(lambda x,y : (x+y,x*y), range(1,6), range(5,0,-1)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "0ccd7d6f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['1', '2', '3', '4', '5', '6', '7', '8', '9']"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 练习：将 a 列表中每个int转换成字符串\n",
    "\n",
    "a = list(range(1,10))\n",
    "\n",
    "list(map(str, a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "9a37c839",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4325789"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 练习：将 a=[4,3,2,5,7,8,9]  转换为 4325789\n",
    "\n",
    "a=[4,3,2,5,7,8,9]\n",
    "\n",
    "# int(''.join(list(map(str, a))))\n",
    "\n",
    "c = a[0]\n",
    "for i in a[1:]:\n",
    "    c = 10*c + i    \n",
    "c\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "86d52877",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4325789"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from functools import reduce\n",
    "\n",
    "a=[4,3,2,5,7,8,9]\n",
    "\n",
    "reduce(lambda x,y: 10*x+y , a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "a5f8cf22",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7257600\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "7257600"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 练习：计算n！\n",
    "\n",
    "n = 5\n",
    "def fac(n):\n",
    "    return 2*reduce(lambda x,y: x*y , range(1,n+1))\n",
    "\n",
    "print(fac(10))\n",
    "\n",
    "def fac2(n):\n",
    "    return reduce(lambda x,y: x*y , range(1,n+1), 2)\n",
    "\n",
    "fac2(10)\n",
    "\n",
    "# 练习：计算2*n！"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "5d46d1e9",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 练习：计算所有人的年龄之和\n",
    "scientists =({'name':'Alan Turing', 'age':105, 'gender':'male'},\n",
    "             {'name':'Dennis Ritchie', 'age':76, 'gender':'male'},\n",
    "             {'name':'Ada Lovelace', 'age':202, 'gender':'female'},\n",
    "             {'name':'Frances E. Allen', 'age':84, 'gender':'female'})\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "097ec7e2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "({'name': 'Alan Turing', 'age': 105, 'gender': 'male'},\n",
       " {'name': 'Dennis Ritchie', 'age': 76, 'gender': 'male'},\n",
       " {'name': 'Ada Lovelace', 'age': 202, 'gender': 'female'},\n",
       " {'name': 'Frances E. Allen', 'age': 84, 'gender': 'female'})"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scientists"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cb2cd43f",
   "metadata": {},
   "outputs": [],
   "source": [
    "def f(x,y):\n",
    "    print(x)\n",
    "    print(y)\n",
    "    print(x + y['age'])\n",
    "    print('----')\n",
    "    return x + y['age']\n",
    "\n",
    "\n",
    "reduce(f, scientists, 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "1f0517c8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'male': ['Alan Turing', 'Dennis Ritchie'],\n",
       " 'female': ['Ada Lovelace', 'Frances E. Allen']}"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 练习：由scientists 得到 \n",
    "# {'male': ['Alan Turing', 'Dennis Ritchie'], 'female': ['Ada Lovelace', 'Frances E. Allen']}\n",
    "\n",
    "scientists =({'name':'Alan Turing', 'age':105, 'gender':'male'},\n",
    "             {'name':'Dennis Ritchie', 'age':76, 'gender':'male'},\n",
    "             {'name':'Ada Lovelace', 'age':202, 'gender':'female'},\n",
    "             {'name':'Frances E. Allen', 'age':84, 'gender':'female'})\n",
    "\n",
    "def f(x,y):\n",
    "    x[y['gender']].append(y['name'])\n",
    "    return x\n",
    "\n",
    "\n",
    "reduce(f, scientists, {'male':[], 'female':[]})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "faee2b9c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'male': ['Alan Turing', 'Dennis Ritchie'],\n",
       " 'female': ['Ada Lovelace', 'Frances E. Allen']}"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 练习：由scientists 得到 \n",
    "# {'male': ['Alan Turing', 'Dennis Ritchie'], 'female': ['Ada Lovelace', 'Frances E. Allen']}\n",
    "scientists =({'name':'Alan Turing', 'age':105, 'gender':'male'},\n",
    "             {'name':'Dennis Ritchie', 'age':76, 'gender':'male'},\n",
    "             {'name':'Ada Lovelace', 'age':202, 'gender':'female'},\n",
    "             {'name':'Frances E. Allen', 'age':84, 'gender':'female'})\n",
    "\n",
    "#x_dict={'male':[],'female':[]}\n",
    "def gender_group(x_dict,y):\n",
    "    x_dict[y['gender']].append(y['name'])\n",
    "    return x_dict\n",
    "\n",
    "result = reduce(gender_group, scientists,{'male':[],'female':[]} )\n",
    "\n",
    "#result = reduce(lambda x_dict,y:x_dict[y['gender']].append(y['name']), scientists,{'male':[],'female':[]} )\n",
    "result\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "729eff3c",
   "metadata": {},
   "outputs": [],
   "source": [
    "a=  [1,2,3]\n",
    "a = a.append(4)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "8bda50b6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "None\n"
     ]
    }
   ],
   "source": [
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "0107b0a1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "贾东晓: 97\n",
      "刘星宇: 97\n"
     ]
    }
   ],
   "source": [
    "# 使用函数将学生姓名和成绩用dict表示\n",
    "def score(name, score):\n",
    "    return {'name': name, 'score': score}\n",
    "\n",
    "# 使用函数输出学生成绩\n",
    "def print_score(stu):\n",
    "    print('{m[name]}: {m[score]}'.format(m = stu))\n",
    "\n",
    "\n",
    "\n",
    "stu1 = score('贾东晓', 97)\n",
    "stu2 = score('刘星宇', 97)\n",
    "\n",
    "print_score(stu1)\n",
    "print_score(stu2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "66738d94",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "贾东晓: 97\n",
      "刘星宇: 97\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('贾东晓', 97)"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "class Student:\n",
    "\n",
    "    def __init__(self, name, score):   \n",
    "        #类的初始化，给对象传入参数\n",
    "        self.name = name   # 属性\n",
    "        self.score = score\n",
    "\n",
    "    def print_score(self):  # 方法\n",
    "        print('{}: {}'.format(self.name, self.score))\n",
    "\n",
    "\n",
    "# 创建一个student对象（类的实例化, Instance）\n",
    "jiadongxiao = Student('贾东晓', 97)  #类的一个实例\n",
    "liuxingyu = Student('刘星宇', 97)\n",
    "\n",
    "jiadongxiao.print_score()\n",
    "liuxingyu.print_score()     \n",
    "\n",
    "jiadongxiao.name, jiadongxiao.score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "e54a932f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "我正在被执行\n",
      "over\n"
     ]
    }
   ],
   "source": [
    "# check: 实例化类（初始化类）的时候会执行`__init__`函数\n",
    "class Test:\n",
    "    def __init__(self):\n",
    "        print('我正在被执行')\n",
    "        print('over')\n",
    "\n",
    "test = Test()  #类的初始化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "65ef2609",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2549602920192\n",
      "2549602920192\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "# check: `self`表示实例对象本身\n",
    "\n",
    "class Test:\n",
    "    def __init__(self):\n",
    "        self.location = id(self)\n",
    "\n",
    "test = Test()\n",
    "print(id(test))\n",
    "print(test.location)\n",
    "print(id(test) == test.location)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "6741bac2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hey, 杨博闻! Congrats, you got 97!\n",
      "Hey, 杨博闻! Congrats, you got 97!\n"
     ]
    }
   ],
   "source": [
    "# 没有给 __init__()传入参数：\n",
    "class Student(object):\n",
    "  \n",
    "  def __init__(self):\n",
    "    self.name = '杨博闻'\n",
    "    self.grade = 97\n",
    "  \n",
    "  def hey(self):\n",
    "    print('Hey, {}! Congrats, you got {}!'.format(self.name, self.grade))\n",
    "\n",
    "xiaoyang = Student()\n",
    "xiaoli = Student()\n",
    "\n",
    "xiaoyang.hey()  # Hey, 杨博闻\n",
    "xiaoli.hey()  # Hey, 杨博闻  和xiaoyang 具有相同的属性\n",
    "\n",
    "# 需求：name 和 grade 在初始化时可以传入不同的值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "22b69489",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hey, 李佳静! Congrats, you got 100!\n"
     ]
    }
   ],
   "source": [
    "# method1  直接改\n",
    "\n",
    "class Student(object):\n",
    "  \n",
    "  def __init__(self):\n",
    "    self.name = '杨博闻'\n",
    "    self.grade = 97\n",
    "  \n",
    "  def hey(self):\n",
    "    print('Hey, {}! Congrats, you got {}!'.format(self.name, self.grade))\n",
    "\n",
    "xiaoyang = Student()\n",
    "xiaoli = Student()\n",
    "\n",
    "xiaoli.name = '李佳静'\n",
    "xiaoli.grade = 100\n",
    "xiaoli.hey()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "2f9d487a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hey, lijiajing! Congrats, you got 100!\n"
     ]
    }
   ],
   "source": [
    "class Student(object):\n",
    "  \n",
    "  def __init__(self, name, grade):\n",
    "    self.name = name\n",
    "    self.grade = grade\n",
    "  \n",
    "  def hey(self):\n",
    "    print('Hey, {}! Congrats, you got {}!'.format(self.name, self.grade))\n",
    "\n",
    "xiaoli = Student('lijiajing', 100)\n",
    "xiaoli.hey()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "f62496a5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "windy\n",
      "ok\n",
      "windy\n"
     ]
    }
   ],
   "source": [
    "class A:\n",
    "    STATUS = 'windy'  # 类变量，类本身和类的对象都可以调用\n",
    "    \n",
    "    def __init__(self, status):\n",
    "        self.status = status  # 实例变量\n",
    "\n",
    "# 创建对象\n",
    "a = A('rainy')\n",
    "b = A('sunny')\n",
    "\n",
    "#A.STATUS v.s. a.STATUS\n",
    "# print(a.STATUS)\n",
    "# print(b.STATUS)\n",
    "# print(A.STATUS) \n",
    "# # 类变量：类本身和类的对象都可以调用； 所有实例共享类变量\n",
    "\n",
    "# # a.status v.s. A.status\n",
    "# print(a.status)\n",
    "# print(A.status)\n",
    "# 实例变量：只能对象调用，类本身不能调用\n",
    "\n",
    "# # 类变量可以修改\n",
    "# A.STATUS='sunny'\n",
    "# print(a.STATUS)\n",
    "# print(b.STATUS)\n",
    "\n",
    "a.STATUS = 'ok'\n",
    "print(A.STATUS)\n",
    "print(a.STATUS)\n",
    "print(b.STATUS)\n",
    "\n",
    "# # a.STATUS, b.STATUS ? \n",
    "# a.status='windy'\n",
    "# print(a.status)\n",
    "# print(b.status)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "f95f5047",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 练习：统计学生人数 \n",
    "# 定义一个学生类，每初始化一次，学生人数加1； \n",
    "# 思路：可以给Student类增加一个类变量，每创建一个实例，该属性自动增加\n",
    "\n",
    "class Student:\n",
    "\n",
    "    count = 0\n",
    "\n",
    "    def __init__(self, name):\n",
    "        self.name = name \n",
    "        Student.count += 1\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "62065dbf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "xiaozhang = Student('xiaozhang')\n",
    "print(xiaozhang.count)\n",
    "\n",
    "xiaoli = Student('xiaoli')\n",
    "xiaoli.count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "3bcb19ad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'c:\\\\Users\\\\illus\\\\OneDrive\\\\GIT\\\\data-analysis\\\\course-coding'"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from os import getcwd\n",
    "\n",
    "getcwd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1484ce53",
   "metadata": {},
   "outputs": [],
   "source": [
    "python XXX.py"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3d860c91",
   "metadata": {},
   "source": [
    "## class 6 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "7c7f23e7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Python', 'python']\n"
     ]
    }
   ],
   "source": [
    "import re\n",
    "\n",
    "text = 'I like Python and python'\n",
    "\n",
    "p=r'[Pp]ython'\n",
    "\n",
    "\n",
    "match_list = re.findall(p,text)\n",
    "\n",
    "print(match_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "0aed7531",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['0.3', '0.50', '0.80', '1.00', '1.30', '1.80']"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cbond1 = '第一年0.3%、第二年0.50%、第三年0.80%、第四年1.00%、第五年1.30%、第六年1.80%'\n",
    "\n",
    "\n",
    "p = r'(\\d\\.\\d{1,2})%'\n",
    "re.findall(p, cbond1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "607a027a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.002990245819091797 0.0\n"
     ]
    }
   ],
   "source": [
    "# Ndarray 和 list 运算速度比较\n",
    "import numpy as np\n",
    "import random\n",
    "import time\n",
    "\n",
    "a = []\n",
    "for i in range(100000):\n",
    "    a.append(random.random())\n",
    "t1 = time.time()\n",
    "sum1 = sum(a)  # 求和\n",
    "t2 = time.time()\n",
    "\n",
    "b=np.array(a)\n",
    "t4=time.time()\n",
    "sum3=np.sum(b)\n",
    "t5=time.time()\n",
    "print(t2-t1,t5-t4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "4a30b281",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1649311383.0238624"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import time\n",
    "time.time()  #1649311363.2032523\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "63fd48ee",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 1 2 3 4 5 6 7 8 9]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "dtype('int32')"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a1 = np.arange(10)\n",
    "print(a1)\n",
    "type(a1)\n",
    "a1.dtype"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "01b1bbbe",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1 2 3]\n",
      "[0 1 2 3 4 5 6 7 8 9]\n"
     ]
    }
   ],
   "source": [
    "print(np.array([1,2,3]))\n",
    "print(np.array(range(10)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2743a763",
   "metadata": {},
   "outputs": [],
   "source": [
    "# np.linspace(start, stop, num=50, endpoint=True)\n",
    "\n",
    "np.linspace(0, 100, 100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "43856d4d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 1 2 3 4 5 6 7 8 9]\n",
      "[1 1 2 3 4 5 6 7 8 9]\n"
     ]
    }
   ],
   "source": [
    "a = np.array(range(10))\n",
    "print(a)\n",
    "a[0] = 1.909\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "4bb67b80",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0. 1. 2. 3. 4. 5. 6. 7. 8. 9.]\n",
      "[1.909 1.    2.    3.    4.    5.    6.    7.    8.    9.   ]\n"
     ]
    }
   ],
   "source": [
    "a = np.array(range(10), dtype = float)\n",
    "print(a)\n",
    "a.dtype\n",
    "a[0] = 1.909\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "1d74e0e5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0. 1. 2. 3. 4. 5. 6. 7. 8. 9.]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "dtype('float64')"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.array(range(10))\n",
    "a = a.astype('float')\n",
    "print(a)\n",
    "a.dtype"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "2222cca8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "list"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# list(a)\n",
    "type(a.tolist())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "6c3e56ad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 1., 1., 1., 1.],\n",
       "       [1., 1., 1., 1., 1.],\n",
       "       [1., 1., 1., 1., 1.],\n",
       "       [1., 1., 1., 1., 1.],\n",
       "       [1., 1., 1., 1., 1.]])"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# np.array([[1,2,3],[4,5,6],[1,7,9]])\n",
    "# np.zeros(shape=(3,5))\n",
    "# np.zeros((3,5))\n",
    "np.ones((5,5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "3328eaf2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ 1  3  5  7  9 11 13 15 17 19]\n",
      "[ 1  5  7  9 11 13 15 17 19]\n"
     ]
    }
   ],
   "source": [
    "a = np.array(range(1,20,2))\n",
    "print(a)\n",
    "a = np.delete(a, 1)\n",
    "print(a)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "f65827cc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 1 2 3 4]\n",
      " [5 6 7 8 9]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([['bad', 'bad', 'bad', 'bad', 'bad'],\n",
       "       ['bad', 'good', 'good', 'good', 'good']], dtype='<U4')"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a  = np.array(range(10))\n",
    "b= a.reshape((2,-1))\n",
    "print(b)\n",
    "# b.reshape(b.size)\n",
    "# b[0:]\n",
    "# b.T\n",
    "# b[0] = 10\n",
    "# print(b)\n",
    "# 条件判断\n",
    "# b[~(b>=5)] = 10\n",
    "# print(b)\n",
    "\n",
    "np.where(b>5, 'good', 'bad')\n",
    "# np.which? "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "2f51de46",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 22 168]\n",
      " [ 18 187]]\n",
      "[[0]\n",
      " [1]]\n",
      "[[1.]\n",
      " [1.]]\n"
     ]
    }
   ],
   "source": [
    "X1 = np.array([[22, 168],\n",
    "               [18,187]])\n",
    "\n",
    "X2 = np.array([[0],\n",
    "               [1]])\n",
    "\n",
    "X3 = np.ones((2,1))\n",
    "print(X1)\n",
    "print(X2)\n",
    "print(X3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "5b44f912",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 22. 168.   0.   1.]\n",
      " [ 18. 187.   1.   1.]]\n"
     ]
    }
   ],
   "source": [
    "a  = np.concatenate([X1,X2,X3], axis = 1)\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "2a5e5d2d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([191., 207.])"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum(a, axis = 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "id": "d734b86a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[10, 15, 11,  8, 11],\n",
       "       [11,  4,  9, 16, 12],\n",
       "       [12, 18, 13, 19,  8]])"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.randint(4,20,(3,5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "id": "89359d42",
   "metadata": {},
   "outputs": [],
   "source": [
    "# one shot game \n",
    "# np.random.seed(407)\n",
    "# 1, 2, 3\n",
    "win_count = 0\n",
    "for i in range(10000):\n",
    "    lianzi = np.array([1,2,3])\n",
    "    car_loc = np.random.randint(1,4,1)\n",
    "    guest_loc = np.random.randint(1,4,1)\n",
    "    car_loc, guest_loc\n",
    "\n",
    "    host_loc = set(lianzi) - set(car_loc) - set(guest_loc)\n",
    "    # print(car_loc, guest_loc, host_loc)\n",
    "    if guest_loc[0]  == car_loc[0]:\n",
    "        # print('win')  \n",
    "        win_count += 1\n",
    "    # else:\n",
    "        # print('lose')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "id": "10bbfde8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3414"
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "win_count/"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "33f5a12d",
   "metadata": {},
   "source": [
    "### pandas"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "id": "06d8d9e2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "id": "847f229f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "a    1\n",
       "dtype: int64"
      ]
     },
     "execution_count": 147,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1 = pd.Series([1,2,3,4], index = list('abcd'))\n",
    "\n",
    "s2 = pd.Series({'a':1, 'b':2, 'c':4, 'd':7})\n",
    "# print(s2)\n",
    "# type(s2)\n",
    "# s2.values\n",
    "# s2.index.tolist()\n",
    "# list(s2.items())\n",
    "# s2[['a','c']] = 10\n",
    "# print(s2)\n",
    "# s2.index = list('edcvt')\n",
    "# s2\n",
    "s2.reindex(index = {'a':'k'})   ?\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "id": "78dd5eea",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "BJ    1\n",
      "SH    2\n",
      "GZ    3\n",
      "HZ    4\n",
      "dtype: int64\n",
      "BJ    11\n",
      "SH    12\n",
      "JN    13\n",
      "WH    14\n",
      "dtype: int64\n",
      "BJ    12.0\n",
      "GZ     NaN\n",
      "HZ     NaN\n",
      "JN     NaN\n",
      "SH    14.0\n",
      "WH     NaN\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "seri1 = pd.Series([1,2,3,4],index=['BJ','SH','GZ','HZ']) \n",
    "seri2 = pd.Series([11,12,13,14],index=['BJ','SH','JN','WH']) \n",
    "\n",
    "# print(seri1)\n",
    "# print(seri2) \n",
    "# print(seri1+seri2)\n",
    "\n",
    "# 过滤数据\n",
    "print(seri1[seri1 <= 3])\n",
    "# # 标量乘法  \n",
    "# print(seri1*2) \n",
    "# # numpy 函数 \n",
    "# print(np.square(seri1)) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "id": "ea9e70dc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>e</th>\n",
       "      <th>r</th>\n",
       "      <th>t</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>a</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>b</th>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>c</th>\n",
       "      <td>10</td>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    e  r  t\n",
       "a   1  2  3\n",
       "b   3  4  5\n",
       "c  10  7  8"
      ]
     },
     "execution_count": 151,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame([[1,2,3],[3,4,5],[10,7,8]], index = list('abc'), columns = list('ert'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "id": "7d8862e9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'name': {0: 1, 1: 2, 2: 3}, 'age': {0: 1, 1: 2, 2: 3}}"
      ]
     },
     "execution_count": 157,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1  = pd.DataFrame({'name':pd.Series([1,2,3]),'age':[1,2,3]})\n",
    "df1.to_dict()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "id": "29e5069e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [1, 2, 3]\n",
       "Index: []"
      ]
     },
     "execution_count": 158,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame(columns = list('123'))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "position": {
    "height": "144.85px",
    "left": "654px",
    "right": "20px",
    "top": "122px",
    "width": "350px"
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
